package com.example.demo.controller;


import com.example.demo.DTO.TokenDTO;
import com.example.demo.DTO.stringtokendto;
import com.example.demo.service.AuthenticationService;
import com.example.demo.util.JwtToken;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@Api(tags = "用户登录接口")
@RequestMapping(value="/token")
@RestController

public class TokenController {

    @Autowired
    private AuthenticationService wx ;
    @PostMapping("/test")
    @ApiOperation(value = "获取用户token",notes = "")
    public Map<String, String> gettToken(@RequestBody @Validated TokenDTO userDate) throws JsonProcessingException {
        HashMap mapoken =new HashMap<String,String>();
        String token =null;
        token = wx.GetTokenWX(userDate);
        mapoken.put("token",token);
        return mapoken;
    }

    @PostMapping("/verify")
    @ApiOperation(value = "验证用户token",notes = "")
    public Map<String,Boolean> verify(@RequestBody stringtokendto token){
        Map<String,Boolean> map = new HashMap<String,Boolean>();
        Boolean valid = JwtToken.verifyToken(token.getToken());
        map.put("is_valid",valid);
        return map ;

    }

}
